package Testhandle_db;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

import java.util.ArrayList;

import handle_db.News_DB_Connector;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import entities.*;


public class News_DB_ConnectorTest {
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		System.out.println("Before class");
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		System.out.println("After class");
	}

	@Before
	public void setUp() throws Exception {
		System.out.println("Before");
	}
	@Test
	public void testGetNews(){
		News_DB_Connector news=new News_DB_Connector();
		News n=new News();
		n.setNews_type(1);
		n.setOwner(1);
		n.setTitle("test");
		Blog b=new Blog(n);
		b.setBlog_context("test");
		int id=news.add_News(b);
		b.setNews_id(id);
		News n2=new State();
		n2.setNews_type(0);
		n2.setOwner(1);
		n2.setTitle("test");
		int id1=news.add_News(n2);
		n2.setNews_id(id1);
		News a=news.get_News_by_news_id(id);
		news=new News_DB_Connector();
		ArrayList<News> t=new ArrayList<News>();
		t=news.get_News(1);
		assertThat(a.equals(b),is(true));
		
		assertThat(t.get(0).equals(b),is(true));
		assertThat(t.get(1).equals(n2),is(true));
	}
	
	@After
	public void tearDown() throws Exception {
		System.out.println("After");
	}
}
